home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13633 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: lince.lander.es!news
  2. From: Marcos Mayorga Aguirre <sparda@lander.es>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help with an array of pointers
  5. Date: Tue, 26 Mar 1996 20:32:32 +0100
  6. Organization: Lander
  7. Message-ID: <31584650.F18@lander.es>
  8. References: <3157FBAF.32A3@village.ios.com>
  9. NNTP-Posting-Host: ppp055.lander.es
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=iso-8859-2
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  14.  
  15. Keith Boruff wrote:
  16. > Suppose I have an array of pointers:
  17. > char *WordPtr[] = {"Jack", "Joe", "Bob"};
  18. > How do I print the address value of each pointer element (i.e., the
  19. > address that each pointer points to)? The only addresses I seem to be
  20. > able to print are the addresses of the array elements themselves.
  21. > I would appreciate any help on this subject. An array of pointers is a
  22. > confusing topic to me and I could use all the help I can get.
  23. > Keith Boruff
  24. > Long Island, NY
  25.  
  26. ok, at this time you have in memory
  27.  
  28.    WordPtr[0]  -->  "Jack"
  29.    WordPtr[1]  -->  "Joe"
  30.    WordPtr[2]  -->  "Bob"
  31.  
  32. if you want view the adresses of "Jack", "joe" and "Bob":
  33.  
  34. printf("Adress of Jack: %P\n",WordPtr[0]);
  35. printf("Adress of Joe: %P\n",WordPtr[1]);
  36. printf("Adress of Bob: %P\n",WordPtr[2]);
  37.  
  38. if you want to print the names of "Jack", "joe" and "Bob":
  39.  
  40.  
  41. printf("%s\n",WordPtr[0]);
  42. printf("%s\n",WordPtr[1]);
  43. printf("%s\n",WordPtr[2]);
  44.  
  45. you can also get the "o" character of "Joe" with WordPtr[1][1] or
  46. with *(WordPtr[1]+1)
  47.  
  48.  
  49. I don't speak english very good, sorry
  50.  
  51. -- 
  52.  
  53.  
  54. ***********************************************************
  55. ***   Marcos Mayorga   <sparda@lander.es>               ***
  56. ***   Busco chica guapa, inteligente, 386 o superior    ***
  57. ***********************************************************
  58.